import '@/assets/gloab/index.css'
import { useEffect } from 'react'
import { useNavigate, useRoutes } from 'react-router-dom'
import router from './router'
let pathname = ''
//实现路由拦截
const Authen = (props:any)=>{
  console.log(props)
  const navigate = useNavigate()
  const {route,children} = props
  const username = sessionStorage.getItem('username')
  pathname = route.props.match.pathname
  useEffect(()=>{
    if(route.props.match.pathname==='/login' && username){
      navigate('/')
    }else if(route.props.match.pathname!=='/login' && username){
      navigate(pathname)
    }else{
      navigate('/login')
    }
  },[pathname])
  return children
}
function App() {
  //const [count, setCount] = useState(0)
  const outlet = useRoutes(router)
  console.log(123,outlet)
  return (
    <>
    <Authen route={outlet}>
      <div>
        {outlet}
      </div>
    </Authen>
    </>
  )
}

export default App
